/******************************************************************************
* File description: MethodStepInput.qml
* Function: 扩增步骤输入框
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-09-03
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

Item {
    id: root

    /* property 定义开始 */
    property string inputText: ""
    property QtObject validator: null

    // 私有
    property bool _inputActiveFocus: false

    // 信号
    signal editFinished(string text);
    signal textEdited(string text);

    // 函数
    function setInputText(text){
        textInput.setInputText(text)
    }

    /* property 定义结束 */

    implicitWidth: 40
    implicitHeight: 23

    Rectangle {
        id: ret
        anchors.fill: parent
        color: "transparent"
        border.width: 1
        border.color: "transparent"

        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            onEntered: {
                ret.color = "#1A2F42CD"
                ret.border.color = "#FF2F42CD"
            }
            onExited: {
                console.log(textInput.focus)
                if(!root._inputActiveFocus){
                    ret.color = "transparent"
                    ret.border.color = "transparent"
                }
            }
        }
    }

    BaseTextInput {
        id: textInput
        anchors.fill: parent
        inputBgColor: "transparent"
        inputBorderWidth: 0
        inputFontPixelSize: 14
        inputText: root.inputText
        inputLeftPadding: 5
        inputRightPadding: 5
        validator: root.validator
        onEditingFinished: root.editFinished(text)
        onTextEdited: root.textEdited(text)
        onInputActiveFocusChanged: {
            if(activeFocus){
                ret.color = "#1A2F42CD"
                ret.border.color = "#FF2F42CD"
            }
            else {
                ret.color = "transparent"
                ret.border.color = "transparent"
            }
            root._inputActiveFocus = activeFocus
        }
    }
}
